package com.ruibang.glass.sale.controller;


import com.ruibang.glass.sale.service.AreaService;
import com.ruibang.glass.sale.entity.Area;
import com.ruibang.glass.sale.domain.req.AreaReq;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @author 宋锦康
 */
@Api(tags = "区域信息接口")
@RestController
@RequestMapping("/api/glass/sale/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取详情", response = ResultBody.class)
    public ResultBody<Area> get(@PathVariable String id) {
        return ResultBody.success(areaService.getById(id));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增实体", response = ResultBody.class)
    public ResultBody add(@RequestBody @ApiParam("实体信息") @Valid Area entity) {
        areaService.save(entity);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改实体", response = ResultBody.class)
    public ResultBody update(@RequestBody Area entity) {
        areaService.updateArea(entity);
        return ResultBody.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除实体", response = ResultBody.class)
    public ResultBody delete(@PathVariable @ApiParam("主键ID") String id) {
        areaService.removeById(id);
        return ResultBody.success();
    }

    @GetMapping("/getAreaList")
    @ApiOperation(value = "获取区域列表", response = ResultBody.class)
    public ResultBody getAreaList() {
        return ResultBody.success(areaService.list());
    }

    @GetMapping("/getByProductLineId/{id}")
    @ApiOperation(value = "根据产线获取区域", response = ResultBody.class)
    public ResultBody getByProductLineId(@PathVariable String id) {
        return ResultBody.success(areaService.getByProductLineId(id));
    }

    @PostMapping("/queryAreas")
    @ApiOperation(value = "查询区域", response = ResultBody.class)
    public ResultBody queryAreas(@RequestBody @ApiParam("实体信息") AreaReq areaReq) {
        return ResultBody.success(areaService.queryAreas(areaReq));
    }
}
